<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" id="aid">
<head>
  <meta charset="utf-8">
  <title>参数设置 / 参数设置</title>
 <link rel="stylesheet" href="../../../css/layui.css" media="all">
   <link rel="stylesheet" type="text/css" href="../../../css/common.css"/>
 	<link rel="stylesheet" type="text/css" href="../../../zTree/zTreeStyle/zTreeStyle.css"/>
 </head>
 <body class="inner-body layui-row layui-col-space10" style="background:#f2f2f2;position: relative; ">
 <div class="body-left treeDiv" style="-webkit-box-orient: vertical;">
 	<!-- <div style="margin: 10px 0px 5px 5px; "><button type="button" class="layui-btn layui-btn-primary" style="width: 185px;">+ 新建部门</button></div> -->
 	<div><ul id="treeDemo" class="ztree"></ul></div>
 	
 </div>
 <!-------默认表格开始----------->
 <div class="body-right">	 
 	<div class="tableHtml" style="height: 100%;background: #FFFFFF; min-width: 800px;">
 		<div class="top-btn">
 			<div class="layui-btn-group">
				<button class="layui-btn" id="addBtn1">新增参数</button>
 				<button class="layui-btn" id="addBtn2">新增参数组</button>
 				<button class="layui-btn" id="editBtn">编辑</button>
 				<button class="layui-btn" id="delBtn">删除</button>
 		 	</div>
 		 	<div class="search-btn-group layui-form">
 				<input type="text"  autocomplete="off" class="layui-input layui-input_" placeholder="请输入门禁开放计划名称" style="width: 180px;">
 		 		<button class="layui-btn layui-btns">查询</button>
 			</div>
 		</div>
 		<div class="tableDiv" >
 			<table id="layui-table" lay-filter="tableBox" class="layui-table"></table>
 		</div>
 	</div>
 </div>
 
 <!-----------------默认表格结束------------>
 
 </body>
 <script type="text/html" id="barDemo">
 	{{# if(d.status == "0"){ }}
 	<span class="layui-badge-dot ayui-bg-orange"></span><a class="" lay-event="choose">未授权</a>
 	{{# } }}
 	{{# if(d.status == "1"){ }}
 	<span class="layui-badge-dot layui-bg-green"></span><a class="" lay-event="shouquan" style="cursor: pointer;">已授权</a>
 	{{# } }}
 </script>
 	
 <script src='../../../layui.all.js'></script>
 <script src="../../../js/common.js" type="text/javascript" charset="utf-8"></script>
 <script src="../../../js/jquery-1.4.4.min.js" type="text/javascript"></script>
 <script src="../../../zTree/jquery.ztree.all.js" type="text/javascript"></script>
 <script src="../../../zTree/jquery.ztree.exhide-3.5.min.js" type="text/javascript"></script>
 <script src="../../../zTree/MtrSearchZTree.js" type="text/javascript"></script>
 <script type="text/javascript">
 	var setting = {
 		view: {
 		            addHoverDom: addHoverDom,//显示操作图标
 		            removeHoverDom: removeHoverDom,//移除图标
 		            selectedMulti: false
 		          },
 		         data: {
 		             simpleData: {
 		                 enable: true
 		             }
 		         },
 		         callback: {
 		             onRename: zTreeOnRename,//修改
 		             onRemove: zTreeOnRemove,//删除
 		             onClick: zTreeOnClickRight,
 					 beforeEditName: beforeEditName,
 					 beforeRemove: beforeRemove,
 					 beforeRename: beforeRename,
 		 
 		         },
 		         edit: {
 		             enable: true,
 		             showRemoveBtn: true,
 		             showRenameBtn: true,
 		             removeTitle: "删除",
 		             renameTitle: "修改"
 		         }
 	};
 		
 		var zNodes =[
 			{ name:"设备运行参数", open:true,
 				children: [
 					{ name:"门禁控制器参数1",open:true,
 						children: [
 							{ name:"参数1"},
 							{ name:"参数2"},
 							{ name:"参数3"},
 						]},
 					{ name:"门禁控制器参数2",
 						children: [
 							{ name:"参数1"},
 							{ name:"参数2"},
 							{ name:"参数3"},
 						]},
 				]},
 				
 		];
 
 		$(document).ready(function(){
 			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
 			new MtrSearchZTree();
 		});
 		
 		var log, className = "dark";
 		var newCount = 1;
 		function addHoverDom(treeId, treeNode) {
 			var sObj = $("#" + treeNode.tId + "_span");
 			if (treeNode.editNameFlag || $("#addBtn_"+treeNode.tId).length>0) return;
 			var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
 				+ "' title='add node' onfocus='this.blur();'></span>";
 			sObj.after(addStr);
 			var btn = $("#addBtn_"+treeNode.tId);
 			if (btn) btn.bind("click", function(){
 				var zTree = $.fn.zTree.getZTreeObj("treeDemo");
 				zTree.addNodes(treeNode, {id:(100 + newCount), pId:treeNode.id, name:"new node" + (newCount++)});
 				return false;
 			});
 		};
 		function removeHoverDom(treeId, treeNode) {
 			$("#addBtn_"+treeNode.tId).unbind().remove();
 		};
 		function zTreeOnRename(e, treeId, treeNode, isCancel) {
 			showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" onRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
 		}
 		function zTreeOnRemove(e, treeId, treeNode) {
 			showLog("[ "+getTime()+" onRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
 		}
 		function showLog(str) {
 			if (!log) log = $("#log");
 			log.append("<li class='"+className+"'>"+str+"</li>");
 			if(log.children("li").length > 8) {
 				log.get(0).removeChild(log.children("li")[0]);
 			}
 		}
 		function getTime() {
 			var now= new Date(),
 			h=now.getHours(),
 			m=now.getMinutes(),
 			s=now.getSeconds(),
 			ms=now.getMilliseconds();
 			return (h+":"+m+":"+s+ " " +ms);
 		}
 		
 		function beforeEditName(treeId, treeNode) {
 			className = (className === "dark" ? "":"dark");
 			showLog("[ "+getTime()+" beforeEditName ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
 			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
 			zTree.selectNode(treeNode);
 			setTimeout(function() {
 				if (confirm("进入节点 '" + treeNode.name + "'编辑状态?")) {
 					setTimeout(function() {
 						zTree.editName(treeNode);
 					}, 0);
 				}
 			}, 0);
 			return false;
 		}
 		function beforeRemove(treeId, treeNode) {
 			className = (className === "dark" ? "":"dark");
 			showLog("[ "+getTime()+" beforeRemove ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name);
 			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
 			zTree.selectNode(treeNode);
 			return confirm("确认删除'" + treeNode.name + "'节点吗?");
 		}
 		function beforeRename(treeId, treeNode, newName, isCancel) {
 			className = (className === "dark" ? "":"dark");
 			showLog((isCancel ? "<span style='color:red'>":"") + "[ "+getTime()+" beforeRename ]&nbsp;&nbsp;&nbsp;&nbsp; " + treeNode.name + (isCancel ? "</span>":""));
 			if (newName.length == 0) {
 				setTimeout(function() {
 					var zTree = $.fn.zTree.getZTreeObj("treeDemo");
 					zTree.cancelEditName();
 					alert("Node name can not be empty.");
 				}, 0);
 				return false;
 			}
 			return true;
 		}
 		// 树的单击事件         
 		    function zTreeOnClickRight(event, treeId, treeNode) {
 		        var treeid = treeNode.id;
 		        $("#hidId").val(treeid);
 		
 		        $("#ifm").attr("src", "FileView?NodeId=" + treeid);
 		    }
 		
 		    function treeShow(data) {
 		        zTreeObj = $.fn.zTree.init($("#test"), setting, data);
 		        zTreeObj.expandAll(true);
 		    }
 //主动加载jquery模块
 layui.use(['jquery', 'layer'], function(){
 	var $ = layui.jquery //重点处
 	,layer = layui.layer;
 	table = layui.table;//表格，注意此处table必须是全局变量
 	$(".treeDiv").height($('.body-right').height()-4);//树高度
 	
 	var arr = [[ 
 	    {type:'checkbox'}
       ,{field: 'pcxlh', title: '门禁开放计划名称'}
       ,{field: 'pc', title: '备注'}
      
     ]];
 	var limitArr =[10,20,30];
 	var urls = '../../../tableJson.js';
 	com.tableRender('#layui-table','tableId','full-53',limitArr,urls,arr);//加载表格,注意tableId是自定义的，在表格重载需要！！
 
     /*-----新增参数-----*/
  	$("#addBtn1").click(function(){	
 	  com.checkOpen("新增参数","html/parm-setting/parm-setting/add-parm.html",['890px', '520px']);
 	})
	/*-----新增参数组-----*/
	$("#addBtn2").click(function(){	
	  com.checkOpen("新增参数组","html/parm-setting/parm-setting/add-parmGrp.html",['890px', '520px']);
	})
 
 	
     /*-----编辑-----*/
  	$("#editBtn").click(function(){	
 	  com.checkOpen("编辑","html/parm-setting/parm-setting/edit.html",['890px', '520px']);
 	})
 	
 	/*-----删除-----*/
 	$("#delBtn").click(function(){	
 		var ix = com.confirm2('确认删除？','温馨提示',['删除', '取消'],[],function(ix){
 			 //do something
 			parent.layer.close(ix);
 		  com.reloadTable();
 		  
 		})
 	});
 	
 	//监听行工具事件
 	  table.on('tool(tableBox)', function(obj){
 	    var data = obj.data;
 	    console.log(obj)
 	    if(obj.event === 'shouquan'){
 	      com.pageOpen("已授权设备","html/cust-mgt/depart-mgt/auth.html",['930px', '500px']);
 	    } else if(obj.event === 'edit'){
 	      
 	    }
 	  });
 
 })	
 </script>
 </html>